/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package app.gui;

import app.gui.scene.SceneHolder;
import app.gui.scene.SceneObserver;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;

/**
 *
 * @author sammael
 */
public class MainMenu extends SceneHolder{
    
    SceneHolder singlePlayerHolder,multiPlayerHolder,exitHolder;
   
    VBox vbox;
    Button singlePlayerButton,multiPlayerButton,exitButton;
    
    
    
    public MainMenu(){
        
        //border = new BorderPane();
        vbox = new VBox(spacing);
        vbox.setAlignment(Pos.CENTER);
        singlePlayerButton = new Button("Pojedynczy Gracz");
        multiPlayerButton = new Button("Wielu Graczy");
        exitButton = new Button("Wyjście");
        singlePlayerButton.setMaxWidth(buttonWidth);
        singlePlayerButton.setOnAction(new EventHandler<ActionEvent>() {
			
			@Override
			public void handle(ActionEvent event) {
				if(singlePlayerHolder==null){
                    singlePlayerHolder = new PlayerDialog(MainMenu.this, true);
                    for(SceneObserver ob : observers){
                        singlePlayerHolder.registerObserver(ob);
                    }
                }
                nextScene = singlePlayerHolder.getScene();
                notifyObservers();
				
			}
		});
        multiPlayerButton.setMaxWidth(buttonWidth);
        multiPlayerButton.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent arg0) {
                if(multiPlayerHolder==null){
                    multiPlayerHolder = new MultiPlayerMenu(MainMenu.this);
                    for(SceneObserver ob : observers){
                        multiPlayerHolder.registerObserver(ob);
                    }
                }
                nextScene = multiPlayerHolder.getScene();
                notifyObservers();
            }
        });
        
        
        exitButton.setMaxWidth(buttonWidth);
        exitButton.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent arg0) {
                ExitScene exit = new ExitScene(MainMenu.this);
                for(SceneObserver o : observers){
                    exit.registerObserver(o);
                }
                nextScene = exit.getScene();
                notifyObservers();
            }
        });
        HelpButton helpButton = new HelpButton();
    	AnchorPane anchor = new AnchorPane();
    	AnchorPane.setBottomAnchor(helpButton, 10.0);
    	AnchorPane.setRightAnchor(helpButton, 10.0);
    	anchor.getChildren().setAll(helpButton);
        vbox.getChildren().setAll(singlePlayerButton,multiPlayerButton,exitButton);
        BorderPane border = new BorderPane();
        border.setCenter(vbox);
        border.setBottom(anchor);
        scene = new Scene(border,rootWidth,rootHeigh);
        
    }
    
    
}
